﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Milestone.Presentation.TemplateSelectors
{
	public class UserTaskTemplateSelector : DataTemplateSelector
	{
		public DataTemplate DefaultTemplate { get; set; }

		public override DataTemplate SelectTemplate( object item, System.Windows.DependencyObject container )
		{
			if( item != null )
			{
				var type = item.GetType();
				var layoutTypeName = String.Format( "{0}.{1}Layout", type.Namespace, type.Name );
				var layoutType = Type.GetType( layoutTypeName, false );
				if( layoutType != null )
				{
					return new DataTemplate()
					{
						VisualTree = new FrameworkElementFactory()
						{
							Type = layoutType
						}
					};
				}
			}

			return this.DefaultTemplate;
		}
	}
}
